﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DoNetToolKit.Patterns.Strategy
{
    class ListEntry<T>
    {
        private T[] arr;
        private int count = -1;
        private int Capacity = 10;
        public ListEntry()
        {
            arr = new T[Capacity];
        }
        public void Add(T t)
        {
            count++;
            if (count >= Capacity)
            {
                Capacity = Capacity * 3 / 2 + 1;
                T[] temp = new T[Capacity];
                Array.Copy(arr, temp, arr.Length);
                arr = temp;
            }
            arr[count] = t;
        }
        public int Count { get { return count + 1; } }

        //public T Get(int index)
        //{
        //    return arr[index];
        //}

        public T this[int index]
        {
            get { return arr[index]; }
            set { arr[index] = value; }
        }

        public void Sort(StrategyCompare c)
        {
            for (int i = 0; i < this.count; i++)
            {
                for (int j = i + 1; j <= this.count; j++)
                {
                    if (c.CompareTo(arr[i], arr[j]) > 0)
                    {
                        T temp = arr[i];
                        arr[i] = arr[j];
                        arr[j] = temp;
                    }
                }
            }
        }
    }
}
